import 'dart:async';
import 'package:fl_chart/fl_chart.dart';
import 'package:get/get.dart';
import 'line_chart3_state.dart';
import 'dart:math' as math;

class LineChart3Logic extends GetxController {
  final LineChart3State state = LineChart3State();

  @override
  void onInit() {
    super.onInit();
    state.timer = Timer.periodic(const Duration(milliseconds: 40), (timer) {
      while (state.sinPoints.length > state.limitCount) {
        state.sinPoints.removeAt(0);
        state.cosPoints.removeAt(0);
      }
      state.sinPoints.add(FlSpot(state.xValue, math.sin(state.xValue)));
      state.cosPoints.add(FlSpot(state.xValue, math.cos(state.xValue)));
      update();
      state.xValue += state.step;
    });
  }


  @override
  void dispose() {
    state.timer.cancel();
    super.dispose();
  }

}
